@extends('admin.main')
@section('head')
    <style>
        .select_box {
            position: relative;
            padding: 0;
            display: inline-block;
            zoom: 1;
            *zoom: 1;
            *display: inline;
        }

        .select_box input:hover {
        }

        .select_box ul {
            width: 150px;
            position: absolute;
            left: 0;
            top: 28px;
            border: 1px solid #85BEE5;
            overflow: hidden;
            display: none;
            background: white;
            z-index: 9999;
        }

        .select_box ul li {
            display: block;
            height: 30px;
            overflow: hidden;
            line-height: 30px;
            padding-left: 5px;
            width: 100%;
            cursor: pointer;
        }

        .select_box ul li:hover {
            background: #d2eaff;
        }
    </style>
@endsection
@section('body')
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>@if(plat_identify() == 'account')我的店铺@else店铺列表@endif</h2>
    </div>
    <div class="cf">
        @if(session('platIdentify') == 'admin')
            <div class="fl">
                <a class="btn" href="{{urlAdmin('single','getShopAdd')}}">开 店</a>
            </div>
            @if(!is_administrator())
            <div class="fl">
                <a class="btn" href="{{urlAdmin('single', 'getSimpleQr')}}">开店二维码</a>
            </div>
            @endif
        @endif

    <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <input type="text" name="keyword" class="search-input" value="{{request('keyword')}}"
                       placeholder="请输入店铺名称">
                <a class="sch-btn" href="javascript:;" id="search" url="{{urlPlat('single','getShop')}}"><i
                            class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                {{--<th class="">ID</th>--}}
                <th class="">店铺名称</th>
                <th class="">账号</th>
                <th class="">状态</th>
                <th class="">店长姓名</th>
                <th class="">商品数量</th>
                <th class="">水票销量 (桶)</th>
                {{--<th class="">店内水桶</th>--}}
                <th class="">押金总 (元)</th>
                {{--<th class="">续费日期</th>--}}
                {{--<th class="">截止日期</th>--}}
                <th class="">操作</th>
            </tr>
            </thead>
            <tbody>
            @if(count($rows['data']))
                @foreach($rows['data'] as $v)
                    <tr>
                        {{--<td>{{$v['id']}}</td>--}}
                        <td>
                            {{$v['shop_name']}}
                            @if($v['status'] == 2)
                                <span style="color: red"> (已到期)</span>
                            @elseif($v['end_time'] - (strtotime(date('Y-m-d')) + 3600*24*7)  < 0)
                                <span style="color: orange"> (即将到期)</span>
                            @endif
                        </td>
                        <td>{{$v['username']}}</td>
                        <td style="color: @if($v['status'] == 1) blue @elseif($v['status'] == 2) orange @else red @endif">{{$v['status_text']}}</td>
                        <td>{{$v['boss_name']}}</td>
                        <td>{{$v['total_goods_num']}}</td>
                        <td>{{$v['total_water_bill_num']}}</td>
                        {{--<td>{{$v['total_bucket_num']-$v['total_back_bucket_num']}}</td>--}}
                        <td>{{$v['deposit']}}</td>
                        {{--<td><span>{{$v['start_time'] ? date('Y-m-d',$v['start_time']) : '--'}}</span></td>--}}
                        {{--<td><span style="color: red">{{$v['end_time'] ? date('Y-m-d',$v['end_time']) : '--'}}</span>--}}
                        </td>
                        <td>
                            <a href="javascript:;" onclick="showInfo({{$v['id']}})">详情</a>
                            @if(plat_identify() == 'admin')
                                <a title="账号"
                                   href="{{urlPlat('single','getAccount',['shop_id'=>$v['id'],'admin_id'=>$v['admin_id']])}}">账号</a>
                                <div class="select_box">
                                    <a href="javascript:;" class="more">更多操作</a>
                                    <ul class="optionBox">
                                        <li>
                                            <a href="javascript:;" onclick="showBillOrder({{$v['id']}})">水票订单</a>
                                        </li>
                                        <li>
                                            <a href="javascript:;" onclick="showOrder({{$v['id']}})">订单列表</a>
                                        </li>
                                        <li>
                                            @if($v['status'] == 1)
                                                <a href="{{urlPlat('single','anyChangeShopStatus',['status'=>0,'id'=>$v['id']])}}"
                                                   class="ajax-get" style="color:orange">禁用</a>
                                            @else
                                                <a href="{{urlPlat('single','anyChangeShopStatus',['status'=>1,'id'=>$v['id']])}}"
                                                   class="ajax-get" style="color:blue">启用</a>
                                            @endif
                                        </li>
                                    </ul>
                                </div>
                            @endif
                            @if(plat_identify() == 'account')
                                <a title="轮播图" href="{{urlPlat('single','getShopSliders',['id'=>$v['id'],'admin_id'=>$v['admin_id']])}}">轮播图</a>
                                <a title="设置" href="{{urlPlat('single','getShopSetting',['id'=>$v['id'],'admin_id'=>$v['admin_id']])}}">设置</a>
                                <a title="广播" href="{{urlPlat('single','getShopNotice',['id'=>$v['id'],'admin_id'=>$v['admin_id']])}}">广播</a>
                                <a title="编辑" href="{{urlPlat('single','getShopEdit',['id'=>$v['id'],'admin_id'=>$v['admin_id']])}}">编辑</a>
                                {{--<a href="{{urlPlat('single','getShopCharge',['id'=>$v['id'],'admin_id'=>$v['admin_id']])}}" style="color: orange">续费</a>--}}
                            @endif
                        </td>
                    </tr>
                @endforeach
            @else
                <td colspan="12" class="text-center"> aOh! 暂时还没有内容!</td>
            @endif
            </tbody>
        </table>
    </div>
    <div class="page">
        @if($rows['last_page']>1)
            <div>
                @if($rows['prev_page_url'])
                    <a class="prev" href="{{$rows['prev_page_url']}}">&lt;&lt;</a>
                @endif
                @if(count($rows['pageNoList']))
                    @foreach($rows['pageNoList'] as $v)
                        @if($rows['current_page'] == $v)
                            <span class="current">{{$v}}</span>
                        @else
                            <a class="num" href="{{urlPlat('single','getShop',['page'=>$v])}}">{{$v}}</a>
                        @endif
                    @endforeach
                @endif
                @if($rows['next_page_url'])
                    <a class="next" href="{{$rows['next_page_url']}}">&gt;&gt;</a>
                @endif
                <span class="rows">共 {{$rows['total']}} 条记录</span>
            </div>
        @endif
    </div>
@endsection

@section('script')

    <script type="text/javascript">
        function showInfo(id) {
            layer.open({
                type: 2,
                title: '店铺详情',
                area: ['450px', '360px'],
                fixed: false, //不固定
                content: '{{urlPlat('single','getShopInfo')}}?shop_id=' + id
            });
        }
        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var query = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (url.indexOf('?') > 0) {
                url += '&' + query;
            } else {
                url += '?' + query;
            }
            window.location.href = url;
        });
        //回车搜索
        $(".search-input").keyup(function (e) {
            if (e.keyCode === 13) {
                $("#search").click();
                return false;
            }
        });

        $(".more").click(function () {
            var thisul = $(this).parent().find("ul");
            if (thisul.css("display") == "none") {
                if (thisul.height() > 180) {
                    thisul.css({height: "180" + "px", "overflow-y": "scroll"})
                };
                thisul.fadeIn("100");
                thisul.hover(function () {
                }, function () {
                    thisul.fadeOut("100");
                })
                thisul.find("li").click(function () {
                    thisul.fadeOut("100");
                }).hover(function () {
                    $(this).addClass("hover");
                }, function () {
                    $(this).removeClass("hover");
                });
            }
            else {
                thisul.fadeOut("fast");
            }

        });

        // 水票订单
        function showBillOrder(shopId){
            layer.open({
                type: 2,
                title: '水票订单',
                area: ['80%','70%'],
                fixed: false,
                content: "{{urlPlat('single','getBillOrder')}}?shop_id=" + shopId
            });
        }

        function showOrder(shopId){
            layer.open({
                type: 2,
                title: '订单列表',
                area: ['80%','70%'],
                fixed: false,
                content: "{{urlPlat('single','getOrder')}}?shop_id=" + shopId
            });
        }

    </script>
@endsection
